package com.ss.android.article.base.feature.detail2.picgroup.view;

import android.animation.Animator;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewConfigurationCompat;
import android.support.v4.view.PagerAdapter;
import android.text.SpannableStringBuilder;
import android.text.style.AbsoluteSizeSpan;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.facebook.drawee.controller.AbstractDraweeControllerBuilder;
import com.facebook.drawee.interfaces.DraweeController;
import com.ss.android.article.base.feature.detail.model.ArticleDetail;
import com.ss.android.article.base.feature.detail.model.ArticleInfo;
import com.ss.android.article.base.feature.detail.model.ImageRecom;
import com.ss.android.article.base.feature.detail.model.GalleryImageInfo;
import com.ss.android.article.base.feature.detail2.event.TitleBarAdEvent;
import com.ss.android.article.base.feature.detail2.view.NewDetailActivity;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.ui.GridViewWithHeaderAndFooter;
import com.ss.android.article.base.ui.ZoomImageView;
import com.ss.android.article.browser.R;
import com.ss.android.common.app.LifeCycleInvoker;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.util.NetworkUtils;
import com.ss.android.image.FrescoUtils;
import com.ss.android.image.Image;
import com.ss.android.image.a.a.TTDraweeControllerBuilder;
import com.ss.android.image.model.ImageInfo;
import com.ss.android.messagebus.SubscriptionRouter;
import com.ss.android.newmedia.util.AppUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class PictureDetailLayout extends RelativeLayout {
    public ViewPager b;
    public a d;
    public Article e;
    public NewDetailActivity f;
    public LinearLayout h;
    public String i;
    public int j;
    public int k;
    public boolean l;
    public boolean m;
    TextView a;
    Resources c;
    PictureDetailLayout$b g;
    float n;
    int o;
    int p;
    ImageRecom q;
    int r;
    int s;
    int t;
    boolean u;
    float v;
    View.OnClickListener w;
    View.OnClickListener x;
    private ArticleDetail A;
    private boolean B;
    private boolean C;
    private boolean D;
    private Animator.AnimatorListener E;
    private Animator.AnimatorListener F;
    private LinearLayout y;
    private ProgressBar z;
    public PictureDetailLayout(Context arg3) {
        super(arg3);
        this.j = 0;
        this.B = true;
        this.o = 0;
        this.C = false;
        this.r = 0;
        this.s = 0;
        this.t = 0;
        this.u = false;
        this.v = 0f;
        this.w = new e(this);
        this.E = new f(this);
        this.F = new com.ss.android.article.base.feature.detail2.picgroup.view.g(this);
        this.x = new com.ss.android.article.base.feature.detail2.picgroup.view.h(this);
        this.a(arg3);
    }
    public PictureDetailLayout(Context arg3, AttributeSet arg4) {
        super(arg3, arg4);
        this.j = 0;
        this.B = true;
        this.o = 0;
        this.C = false;
        this.r = 0;
        this.s = 0;
        this.t = 0;
        this.u = false;
        this.v = 0f;
        this.w = new e(this);
        this.E = new f(this);
        this.F = new com.ss.android.article.base.feature.detail2.picgroup.view.g(this);
        this.x = new com.ss.android.article.base.feature.detail2.picgroup.view.h(this);
        this.a(arg3);
    }

    public final void a(boolean arg3) {
        ProgressBar v1 = this.z;
        int v0 = arg3 ? 0 : 8;
        UIUtils.setVisibility(((View) v1), v0);
    }

    public final void a() {
        if (this.e != null && this.e.y != null && this.e.y.size() != 0) {
            int v0 = this.b.getCurrentItem();
            if (v0 < this.e.y.size()) {
                Object v0_1 = this.e.y.get(v0);
                SpannableStringBuilder v1 = new SpannableStringBuilder();
                this.setPageIndex(v1);
                if (this.C) {
                    this.setOriginalIcon(v1);
                }

                v1.append(((GalleryImageInfo) v0_1).subAbstract);
                this.a.setText(((CharSequence) v1), TextView.BufferType.SPANNABLE);
                this.h.getViewTreeObserver().addOnGlobalLayoutListener(new com.ss.android.article.base.feature.detail2.picgroup.view.d(this));
            }
        }
    }

    public final boolean a(int arg9, int arg10, boolean arg11) {
        boolean v0 = false;
        long v6 = 200;
        if (!this.u) {
            d v1 = this.d.d();
            if (v1 != null) {
                float v0_1 = this.getHeight() != 0 ? Math.max(1f - (((float) Math.abs(arg9))) * 10f / (((float) this.getHeight())), 0f) : (((float) arg10)) / 255f;
                if (arg11) {
                    v1.a.animate().setDuration(v6).translationY(((float) arg9));
                    this.h.animate().setDuration(v6).translationY(((float) Math.abs(arg9))).alpha(v0_1);
                } else {
                    v1.a.setTranslationY(((float) arg9));
                    this.h.setAlpha(v0_1);
                }
            } else {
                if (!this.l) {
                } else if (this.d.e == null) {
                } else if (arg11) {
                    this.d.e.animate().setDuration(v6).translationY(((float) arg9));
                } else {
                    this.d.e.setTranslationY(((float) arg9));
                }
            }

            v0 = true;
        } else if (this.r < this.s - this.t) {
            if ((((float) arg9)) + this.v >= 0f && (((float) arg9)) + this.v <= (((float) (this.s - this.r)))) {
                this.a.setTranslationY((((float) arg9)) + this.v);
                return v0;
            }

            if ((((float) arg9)) + this.v < 0f && this.a.getTranslationY() > 0f) {
                this.a.setTranslationY(0f);
                return v0;
            }

            if ((((float) arg9)) + this.v <= (((float) (this.s - this.r)))) {
                return v0;
            }

            if (this.a.getTranslationY() >= (((float) arg9)) + this.v) {
                return v0;
            }

            this.a.setTranslationY(((float) (this.s - this.r)));
        }

        return v0;
    }

    public final boolean a(int arg6, float arg7) {
        boolean v0_1;
        int v4 = -1;
        d v0 = this.d.d();
        if (v0 != null) {
            switch (arg6) {
                case 0: {
                    if ((v0.a.b()) && !ViewCompat.canScrollHorizontally(this.b, v4)) {
                        return true;
                    }
                    return false;
                }
                case 2: {
                    if ((v0.a.b()) && (!this.a.isShown() || arg7 < this.h.getY() || !ViewCompat.canScrollVertically(this.a, v4))) {
                        return true;
                    }
                    return false;
                }
                case 3: {
                    label_25:
                    if ((v0.a.b()) && (!this.a.isShown() || arg7 < this.h.getY() || !ViewCompat.canScrollVertically(this.a, 1))) {
                        return true;
                    }
                    v0_1 = false;
                    return v0_1;
                }
            }

            v0_1 = false;
            return v0_1;
        } else {
            View v0_2 = this.d.a;
            if (v0_2 != null && ((v0_2.getTag() instanceof PictureDetailLayout$c)) && (arg6 == 2 || arg6 == 3)) {
                if (!ViewCompat.canScrollVertically(((PictureDetailLayout$c) v0_2.getTag()).mRelatedPictureGridView, v4)) {
                    return true;
                }

                return false;
            }

            v0_1 = false;
        }

        return v0_1;
    }

    public final boolean a(int arg9, Animator.AnimatorListener arg10) {
        int v0_1;
        long v6 = 200;
        boolean v0 = false;
        if (!this.u) {
            if (arg10 == null) {
                return true;
            }

            d v2 = this.d.d();
            if (v2 != null) {
                v0_1 = v2.a.getHeight();
                if (arg9 < 0) {
                    v0_1 = -v0_1;
                }

                v2.a.animate().translationY(((float) v0_1)).setListener(arg10);
                this.h.animate().translationY(((float) Math.abs(v0_1))).alpha(0f);
            } else {
                if (!this.l) {
                } else if (this.d.e == null) {
                } else {
                    v0_1 = this.d.e.getHeight();
                    if (arg9 < 0) {
                        v0_1 = -v0_1;
                    }
                    this.d.e.animate().translationY(((float) v0_1)).setListener(arg10);
                }
            }
            v0 = true;
        } else if (this.r >= this.s - this.t) {
            this.u = false;
        } else {
            if ((((float) arg9)) + this.v < 0f || (((float) arg9)) + this.v > (((float) (this.s - this.r)))) {
                if ((((float) arg9)) + this.v < 0f && this.a.getTranslationY() > 0f) {
                    this.a.setTranslationY(0f);
                } else if ((((float) arg9)) + this.v <= (((float) (this.s - this.r)))) {
                } else if (this.a.getTranslationY() >= (((float) arg9)) + this.v) {
                } else {
                    this.a.setTranslationY(((float) (this.s - this.r)));
                }
            } else if (arg9 < 0) {
                ViewCompat.animate(this.a).setDuration(v6).translationY(0f).start();
            } else {
                ViewCompat.animate(this.a).setDuration(v6).translationY(((float) (this.s - this.r))).start();
            }

            this.u = false;
        }

        return v0;
    }

    private void a(Context arg3) {
        if (arg3 != null) {
            this.n = ((float) ViewConfigurationCompat.getScaledPagingTouchSlop(ViewConfiguration.get(arg3)));
            this.f = (NewDetailActivity) arg3;
            LayoutInflater.from(arg3);
            View.inflate(arg3, R.layout.gd, ((ViewGroup) this));
            this.y = this.findViewById(com.ss.android.article.browser.R.id.a68);
            this.a = this.findViewById(com.ss.android.article.browser.R.id.a67);
            this.b = this.findViewById(com.ss.android.article.browser.R.id.view_pager);
            this.z = this.findViewById(com.ss.android.article.browser.R.id.sf);
            this.h = this.findViewById(com.ss.android.article.browser.R.id.a66);
            this.c = arg3.getResources();
            this.B = true;
            this.a.setOnTouchListener(new com.ss.android.article.base.feature.detail2.picgroup.view.a(this));
            this.r = ((int) UIUtils.dp2px(arg3, 177f));
            UIUtils.dp2px(arg3, 45f);
            this.t = ((int) UIUtils.dp2px(arg3, 12f));
            this.b.setPageMargin(20);
            this.y.setOnClickListener(this.w);
        }
    }

    final void a(View arg4) {
        if (!NetworkUtils.isNetworkAvailable(this.f)) {
            UIUtils.showImageToast(this.f, R.drawable.close_popup_textpage, R.string.net_unvailable);
        } else if (arg4 != null && this.d != null) {
            d v0 = this.d.d();
            if (v0 != null && v0.a != null) {
                DraweeController v1 = v0.a.getController();
                if (v1 != null) {
                    v0.a.setController(v1);
                    v0.a(true);
                    UIUtils.setVisibility(v0.c, 0);
                }
            }
        }
    }

    public final void a(String arg3) {
        if (!android.support.design.a.isTextEmpty(arg3)) {
            MobClickCombiner.onEvent(this.f, "slide_detail", arg3);
        }
    }

    public final void b(boolean arg2) {
        if (this.d != null) {
            this.d.a(arg2);
        }
    }

    public final void b() {
        long v2 = 220;
        if (this.f.isViewValid()) {
            this.f.startTitleBarAnimation(this.B);
        }

        if (this.B) {
            this.h.animate().alpha(0f).setDuration(v2).setListener(this.F);
        } else {
            this.h.animate().alpha(1f).setDuration(v2).setListener(this.E);
        }

        boolean v0 = !this.B ? true : false;
        this.B = v0;
        String v0_1 = this.B ? "show_content" : "hide_content";
        this.a(v0_1);
    }

    public final void c(boolean arg3) {
        LinearLayout v1 = this.y;
        int v0 = arg3 ? 0 : 4;
        UIUtils.setVisibility(((View) v1), v0);
    }

    protected void dispatchDraw(Canvas arg2) {
        if (this.getVisibility() == View.VISIBLE) {
            super.dispatchDraw(arg2);
        }
    }

    public float getReadPct() {
        float v0 = this.k > 0 ? (((float) (this.p + 1))) / (((float) this.k)) : 0f;
        return v0;
    }

    public void setArticleDetail(ArticleDetail arg1) {
        this.A = arg1;
    }

    public void setBindArticleInfo(ArticleInfo arg11) {
        if (this.d != null) {
            a v0 = this.d;
            List v1 = arg11.relatedGalleryList;
            if (v0.f.f != null && v0.f.e != null && v1.size() != 0) {
                if (v0.d == null) {
                    v0.d = new com.ss.android.article.base.feature.detail.presenter.v(v0.f.f, v1, v0.f.e);
                } else {
                    com.ss.android.article.base.feature.detail.presenter.v v2 = v0.d;
                    if (v2.d != null) {
                        v2.d.clear();
                    }

                    v2.d = v1;
                    v2.notifyDataSetChanged();
                }

                v0.c = v1;
                if (v0.f.d != null) {
                    v0.f.d.notifyDataSetChanged();
                }

                v0.f.a();
            }

            a v9 = this.d;
            ImageRecom v0_1 = arg11.F;
            if (v0_1 != null && (v0_1.isValid())) {
                v9.f.q = v0_1;
                JSONObject v8 = new JSONObject();
                try {
                    v8.put("log_extra", v9.f.q.logExtra);
                } catch (JSONException v0_2) {
                    v0_2.printStackTrace();
                }

                MobClickCombiner.onEvent(v9.f.f, "embeded_ad", "load_finish", v9.f.q.id, 0, v8);
            }

            v9.notifyDataSetChanged();
        }
    }

    public void setBottomLayoutVisibility(int arg2) {
        this.h.setVisibility(arg2);
    }

    public void setCallback(PictureDetailLayout$b arg1) {
        this.g = arg1;
    }

    public void setGoDetailLabel(String arg1) {
        this.i = arg1;
    }

    public void setOriginal(boolean arg1) {
        this.C = arg1;
    }

    private void setOriginalIcon(SpannableStringBuilder arg5) {
        if (arg5 != null) {
            int v0 = arg5.length();
            arg5.append("icon");
            com.ss.android.article.base.ui.j v1 = new com.ss.android.article.base.ui.j(this.f, R.drawable.t1);
            v1.b = ((int) UIUtils.dp2px(this.f, 8f));
            arg5.setSpan(v1, v0, arg5.length(), 33);
        }
    }

    public void setPageIndex(SpannableStringBuilder arg6) {
        if (this.d != null && this.b != null && this.e.y != null) {
            String v0 = this.b.getCurrentItem() + 1 + "/" + this.e.y.size();
            int v1 = v0.indexOf("/");
            int v2 = v0.length();
            arg6.append(((CharSequence) v0));
            arg6.setSpan(new AbsoluteSizeSpan(((int) TypedValue.applyDimension(2, 12f, this.c.getDisplayMetrics())), false), v1, v2, 33);
            arg6.append(" ");
        }
    }

    public void setPageVisibility(int arg11) {
        long v6 = 0;
        int v3 = 8;
        if (this.d == null) {
            return;
        }

        if (this.f.isFinishing()) {
            return;
        }

        int v2 = this.d.c(arg11);
        boolean v0 = v2 == 3 ? true : false;
        this.l = v0;
        v0 = v2 == 2 ? true : false;
        this.m = v0;
        SubscriptionRouter.c(new TitleBarAdEvent());
        switch (v2) {
            case 0:
            case 1: {
                if (this.A != null) {
                    this.f.setUserAvatar(this.A.avatarUrl);
                    this.f.e(this.A.userVerified);
                }

                if (this.B) {
                    this.f.setDetailTitleBarVisible(true);
                    this.f.setDetailToolBarVisible(true);
                    this.setBottomLayoutVisibility(0);
                    break;
                }

                this.f.setDetailTitleBarVisible(false);
                this.f.setDetailToolBarVisible(false);
                break;
            }
            case 2: {
                this.f.setDetailToolBarVisible(false);
                if (this.q == null || (android.support.design.a.isTextEmpty(this.q.label))) {
                    this.f.b(this.f.getString(com.ss.android.article.browser.R.string.ad_label_new));
                } else {
                    this.f.b(this.q.label);
                }
                this.h.animate().cancel();
                this.setBottomLayoutVisibility(v3);
                if (this.q != null && !this.D) {
                    JSONObject v8 = new JSONObject();
                    try {
                        v8.put("log_extra", this.q.logExtra);
                    } catch (JSONException v0_2) {
                        v0_2.printStackTrace();
                    }

                    if (this.q.trackUrlList != null && !this.q.trackUrlList.isEmpty()) {
                        AppUtil.a(this.q.trackUrlList, this.getContext());
                    }

                    MobClickCombiner.onEvent(this.getContext(), "embeded_ad", "show", this.q.id, v6, v8);
                    this.D = true;
                }
                break;
            }
            case 3: {
                this.f.setDetailToolBarVisible(true);
                this.f.b(this.f.getString(com.ss.android.article.browser.R.string.recommend_picture));
                this.h.animate().cancel();
                this.setBottomLayoutVisibility(v3);
                long v0_1 = this.e.itemId;
                long v4 = this.e.groupId;
                JSONObject v8 = new JSONObject();
                try {
                    v8.put("item_id", v0_1);
                } catch (JSONException v0_2) {
                }

                MobClickCombiner.onEvent(this.f, "slide_detail", "related_show", v4, v6, v8);
                break;
            }
        }

        if (this.d != null) {
            this.d.a(this.l);
        }

        this.f.isViewValid();
    }

    public interface PictureDetailLayout$b {
        void q();

        void r();
    }

    public static final class a extends PagerAdapter {
        public final PictureDetailLayout f;
        public List b;
        View a;
        List c;
        com.ss.android.article.base.feature.detail.presenter.v d;
        View e;
        private LayoutInflater g;
        private LinkedList h;
        private int i;

        public a(PictureDetailLayout arg3, Context arg4, Article arg5) {
            this.f = arg3;
            this.h = new LinkedList();
            this.b = new ArrayList();
            this.i = -1;
            if (arg4 != null && arg5 != null) {
                this.g = LayoutInflater.from(arg4);
                if (arg5.y != null && arg5.y.size() > 0) {
                    this.b.addAll(arg5.y);
                    arg3.k = this.b.size();
                }
            }
        }

        public final void a(boolean arg2) {
            if (this.d != null) {
                this.d.e = arg2;
                if (arg2) {
                    this.d.onResume();
                } else {
                    this.d.onPause();
                }
            }
        }

        private void a(d arg4, ImageInfo imageInfo) {
            if (imageInfo != null) {
                Image image = android.support.design.a.imageInfo2Image(imageInfo);
                if (image != null) {
                    AbstractDraweeControllerBuilder draweeControllerBuilder = android.support.design.a.sTTDraweeControllerBuilderSupplier.get().setAutoPlayAnimations();
                    draweeControllerBuilder.mTapToRetryEnabled = true;
                    draweeControllerBuilder = draweeControllerBuilder
                            .getThis()
                            .setFirstAvailableImageRequests(FrescoUtils.buildImageRequests(image));
                    if (arg4.a.getController() != null) {
                        draweeControllerBuilder.setOldController(arg4.a.getController());
                    }

                    arg4.a.setController(((TTDraweeControllerBuilder) draweeControllerBuilder).buildController());
                    arg4.a.setFitToScreen(true);
                    arg4.a.setHierarchy(new m(this, arg4));
                }
            }
        }

        public final int getCount() {
            int v0 = 0;
            if (this.b != null) {
                v0 = this.b.size();
                if (this.c != null && this.c.size() > 0) {
                    ++v0;
                }

                if (this.f.q == null) {
                    return v0;
                }

                if (!this.f.q.isValid()) {
                    return v0;
                }

                ++v0;
            }

            return v0;
        }

        public final int getItemPosition(Object arg4) {
            int v1 = -2;
            Object v0 = null;
            if ((arg4 instanceof View)) {
                v0 = ((View) arg4).getTag(com.ss.android.article.browser.R.id.picture_detail_item_position);
            }

            int v0_1 = (v0 instanceof Integer) ? ((Integer) v0).intValue() : v1;
            return v0_1;
        }

        public final Object instantiateItem(ViewGroup arg13, int arg14) {
            View v1_2 = null;
            d v1_1;
            View v2_1;
            d v2;
            PictureDetailLayout$c v0_5;
            Object v0 = null;
            Object v1 = arg14 >= this.f.k || (this.h.isEmpty()) ? v0 : this.h.removeFirst();
            switch (this.c(arg14)) {
                case 2: {
                    if (this.f.q == null) {
                        break;
                    }

                    v2 = null;
                    if (v1 == null) {
                        v2_1 = this.g.inflate(com.ss.android.article.browser.R.layout.picture_detail_recommend, arg13, false);
                        v1_1 = new d((byte) 0);
                        v1_1.a = v2_1.findViewById(com.ss.android.article.browser.R.id.zoomimageview);
                        v1_1.b = v2_1.findViewById(com.ss.android.article.browser.R.id.picture_item_retry_layout);
                        v1_1.c = v2_1.findViewById(com.ss.android.article.browser.R.id.picture_item_progress_bar);
                        v1_1.e = v2_1.findViewById(com.ss.android.article.browser.R.id.picture_recom_border);
                        v2_1.setTag(com.ss.android.article.browser.R.id.picture_detail_holder_tag, v1_1);
                        v2_1.setTag(com.ss.android.article.browser.R.id.picture_detail_item_position, Integer.valueOf(arg14));
                        v1_1.b.setOnClickListener(this.f.w);
                        v0 = v1_1;
                        v1_2 = v2_1;
                    } else {
                        v0 = ((View) v1).getTag(com.ss.android.article.browser.R.id.picture_detail_holder_tag);
                        if ((v0 instanceof d)) {

                        } else {
                            v0 = v2;
                        }
                        v1_2 = (View) v1;
                    }

                    if (v0 == null) {
                        break;
                    }

                    UIUtils.setVisibility(((d) v0).b, 8);
                    UIUtils.setVisibility(((d) v0).c, 0);
                    UIUtils.setVisibility(((d) v0).e, 8);
                    ImageInfo v2_3 = this.f.q.mImageInfo;
                    this.a(((d) v0), v2_3);
                    ((d) v0).a.setMyOnClickListener(new j(this));
                    ((d) v0).a.setOnLongClickListener(new k(this, v2_3));
                    if (this.d != null && this.d.getCount() > 0) {
                        UIUtils.setVisibility(((d) v0).e, 0);
                        ((d) v0).e.setOnClickListener(new l(this));
                    }

                    ((d) v0).a.setFitToWidth(true);
                    break;
                }
                case 3: {
                    if (this.e == null) {
                        this.e = this.g.inflate(com.ss.android.article.browser.R.layout.picture_detail_related_image_layout, arg13, false);
                        PictureDetailLayout$c v1_3 = new PictureDetailLayout$c((byte) 0);
                        v1_3.mRelatedPictureGridView = this.e.findViewById(com.ss.android.article.browser.R.id.related_picture_gridview);
                        v2_1 = new View(this.f.f);
                        View v3_1 = new View(this.f.f);
                        ViewGroup.LayoutParams v0_3 = new ViewGroup.LayoutParams(-1, this.f.c.getDimensionPixelOffset(R.dimen.h4) - this.f.c.getDimensionPixelOffset(R.dimen.pic_detail_related_picture_vertical_gap));
                        v2_1.setLayoutParams(v0_3);
                        v3_1.setLayoutParams(v0_3);
                        GridViewWithHeaderAndFooter v4 = v1_3.mRelatedPictureGridView;
                        ListAdapter adapter = v4.getAdapter();
                        if (adapter != null && !(adapter instanceof com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.c)) {
                            throw new IllegalStateException("Cannot add header view to grid -- setAdapter has already been called.");
                        }

                        ViewGroup.LayoutParams v5 = v2_1.getLayoutParams();
                        com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.a v6 = new com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.a((byte) 0);
                        com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.b v7 = new com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.b(v4, v4.getContext());
                        if (v5 != null) {
                            v2_1.setLayoutParams(new FrameLayout.LayoutParams(v5.width, v5.height));
                            v7.setLayoutParams(new AbsListView.LayoutParams(v5.width, v5.height));
                        }

                        v7.addView(v2_1);
                        v6.a = v2_1;
                        v6.b = v7;
                        v6.c = true;
                        v4.c.add(v6);
                        if (adapter != null) {
                            ((com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.c) adapter).a.notifyChanged();
                        }

                        GridViewWithHeaderAndFooter v2_4 = v1_3.mRelatedPictureGridView;
                        adapter = v2_4.getAdapter();
                        if (adapter != null && !(adapter instanceof com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.c)) {
                            throw new IllegalStateException("Cannot add header view to grid -- setAdapter has already been called.");
                        }

                        ViewGroup.LayoutParams v4_1 = v3_1.getLayoutParams();
                        com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.a v5_1 = new com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.a((byte) 0);
                        com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.b v6_1 = new com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.b(v2_4, v2_4.getContext());
                        if (v4_1 != null) {
                            v3_1.setLayoutParams(new FrameLayout.LayoutParams(v4_1.width, v4_1.height));
                            v6_1.setLayoutParams(new AbsListView.LayoutParams(v4_1.width, v4_1.height));
                        }

                        v6_1.addView(v3_1);
                        v5_1.a = v3_1;
                        v5_1.b = v6_1;
                        v5_1.c = true;
                        v2_4.d.add(v5_1);
                        if (adapter != null) {
                            ((com.ss.android.article.base.ui.GridViewWithHeaderAndFooter.c) adapter).a.notifyChanged();
                        }

                        this.e.setTag(v1_3);
                        v0_5 = v1_3;
                    } else {
                        v0_5 = (PictureDetailLayout$c) this.e.getTag();
                    }

                    if (v0_5 != null && this.d != null) {
                        v0_5.mRelatedPictureGridView.setAdapter(this.d);
                        if (this.f.e != null && this.f.f != null) {
                            this.d.f = android.support.design.a.a(this.f.e.groupId, this.f.e.itemId, null);
                            this.d.a(v0_5.mRelatedPictureGridView);
                            v0_5.mRelatedPictureGridView.setRecyclerListener(this.d);
                            if ((this.f.f instanceof LifeCycleInvoker)) {
                                NewDetailActivity v0_6 = this.f.f;
                                ((LifeCycleInvoker) v0_6).unregisterLifeCycleMonitor(this.d);
                                ((LifeCycleInvoker) v0_6).registerLifeCycleMonitor(this.d);
                            }
                        }
                    }

                    v1_2 = this.e;
                    break;
                }
                default: {
                    v2 = null;
                    if (v1 == null) {
                        v2_1 = this.g.inflate(com.ss.android.article.browser.R.layout.picture_detail_item, arg13, false);
                        v1_1 = new d((byte) 0);
                        v1_1.a = v2_1.findViewById(com.ss.android.article.browser.R.id.zoomimageview);
                        v1_1.b = v2_1.findViewById(com.ss.android.article.browser.R.id.picture_item_retry_layout);
                        v1_1.c = v2_1.findViewById(com.ss.android.article.browser.R.id.picture_item_progress_bar);
                        v2_1.setTag(com.ss.android.article.browser.R.id.picture_detail_holder_tag, v1_1);
                        v2_1.setTag(com.ss.android.article.browser.R.id.picture_detail_item_position, Integer.valueOf(arg14));
                        v1_1.b.setOnClickListener(this.f.w);
                        d v11 = v1_1;
                        v1_2 = v2_1;
                        v2 = v11;
                    } else {
                        v0 = ((View) v1).getTag(com.ss.android.article.browser.R.id.picture_detail_holder_tag);
                        if ((v0 instanceof d)) {
                            v2 = (PictureDetailLayout.d) v0;
                        }
                        v1_2 = (View) v1;
                    }

                    if (v2 == null) {
                        break;
                    }

                    UIUtils.setVisibility(v2.b, 8);
                    UIUtils.setVisibility(v2.c, 0);
                    GalleryImageInfo v3 = this.b(arg14);
                    ImageInfo v0_1 = null;
                    if (v3 != null) {
                        v0_1 = v3.subImage;
                    }

                    if (v2.a == null) {
                        break;
                    }

                    if (v0_1 == null) {
                        break;
                    }

                    if (!v0_1.isValid()) {
                        break;
                    }

                    this.a(v2, v0_1);
                    v2.a.setMyOnClickListener(this.f.x);
                    v2.a.setOnLongClickListener(new com.ss.android.article.base.feature.detail2.picgroup.view.i(this, arg14));
                    break;
                }
            }

            arg13.removeView(v1_2);
            arg13.addView(v1_2);
            v1_2.setTag(com.ss.android.article.browser.R.id.picture_detail_item_position, Integer.valueOf(arg14));
            return v1_2;
        }

        public final void destroyItem(ViewGroup arg2, int arg3, Object arg4) {
            if ((arg4 instanceof View)) {
                arg2.removeView(((View) arg4));
                if (arg3 < this.f.k) {
                    this.h.add(arg4);
                }
            }
        }

        public final boolean isViewFromObject(View arg2, Object arg3) {
            boolean v0 = arg2 == (((View) arg3)) ? true : false;
            return v0;
        }

        public final GalleryImageInfo b(int arg2) {
            GalleryImageInfo v0_1;
            if (this.b == null || arg2 >= this.b.size() || arg2 < 0) {
                v0_1 = null;
            } else {
                v0_1 = (GalleryImageInfo) this.b.get(arg2);
            }

            return v0_1;
        }

        public final void setPrimaryItem(ViewGroup arg3, int arg4, Object arg5) {
            if (this.i != arg4 && ((arg5 instanceof View))) {
                this.i = arg4;
                PictureDetailLayout v0 = this.f;
                if (arg4 <= this.f.j) {
                    arg4 = this.f.j;
                }

                v0.j = arg4;
                this.a = ((View) arg5);
                d v0_1 = this.d();
                if (v0_1 == null) {
                    return;
                }

                if (!v0_1.d) {
                    return;
                }

                if (!NetworkUtils.isNetworkAvailable(this.f.f)) {
                    return;
                }

                this.f.a(v0_1.b);
            }
        }

        public final int c(int arg3) {
            int v0 = this.f.k;
            if (this.f.q != null && (this.f.q.isValid())) {
                ++v0;
            }

            if (arg3 == 0) {
                v0 = 0;
            } else {
                if (this.f.q != null && (this.f.q.isValid()) && arg3 == v0 - 1) {
                    return 2;
                }

                if (arg3 == v0) {
                    return 3;
                }

                v0 = 1;
            }

            return v0;
        }

        final d d() {
            Object v1_1 = null;
            d v1 = null;
            if (this.a != null) {
                Object v0 = this.a.getTag(com.ss.android.article.browser.R.id.picture_detail_holder_tag);
                if (!(v0 instanceof d)) {
                    v0 = v1;
                }

                v1_1 = v0;
            }

            return ((d) v1_1);
        }
    }

    static final class PictureDetailLayout$c {
        GridViewWithHeaderAndFooter mRelatedPictureGridView;

        PictureDetailLayout$c(byte arg1) {
            this();
        }

        private PictureDetailLayout$c() {

        }
    }

    static final class d {
        ZoomImageView a;
        LinearLayout b;
        ProgressBar c;
        boolean d;
        PictureRecommendBorderLayout e;

        d(byte arg1) {
            this();
        }

        private d() {

        }

        final void a(boolean arg5) {
            int v2 = 8;
            int v1 = 0;
            boolean v0 = !arg5 ? true : false;
            this.d = v0;
            ZoomImageView v3 = this.a;
            int v0_1 = arg5 ? 0 : v2;
            UIUtils.setVisibility(((View) v3), v0_1);
            LinearLayout v0_2 = this.b;
            if (arg5) {
                v1 = v2;
            }

            UIUtils.setVisibility(((View) v0_2), v1);
        }
    }
}

